//
//  MainTabBar.swift
//  Weobo
//
//  Created by 史亚洲 on 16/1/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit


class MainTabBar: UITabBar {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(plusBtn)
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        
        //设置宽高
        let w = self.bounds.size.width/5
        let h = self.bounds.size.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        var index: CGFloat = 0
        
        //遍历subViews
        for subview in subviews {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
                subview.frame = CGRectOffset(rect, w * index, 0)
                index += index == 1 ? 2 : 1
          
                       }

          
        }
        plusBtn.frame = CGRectOffset(rect, 2 * w, 0)
     
    }
    
    //1.懒加载加号按钮
    lazy var plusBtn: UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button_highlighted")
    
  
}
